home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-FormCmnCF.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  55.0 KB  |  1,900 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.     
  4. //**********************GLOBAL VARS********************
  5.  
  6. // intialize labels
  7. var TEXTFIELD     =  MM.LABEL_TextField;
  8. var HIDDENFIELD   =  MM.LABEL_HiddenField;
  9. var PASSWORDFIELD =  MM.LABEL_PasswordField;
  10. var PASSWORD      =  MM.LABEL_Password;
  11. var FILEFIELD     =  MM.LABEL_FileField;
  12. var TEXTAREA      =  MM.LABEL_TextArea;
  13. var MENU          =  MM.LABEL_Menu;
  14. var CHECKBOX      =  MM.LABEL_CheckBox;
  15. var RADIOGROUP    =  MM.LABEL_RadioGroup;
  16. var STATICTEXT    =  MM.LABEL_Text;
  17.  
  18. var TEXT          =  "',none,NULL";
  19. var NUMERIC       =  "none,none,NULL";
  20. var DATE          =  "',none,NULL";
  21. var DATEMSACCESS  =  "#,none,NULL";
  22. var CHECKBOXYN    =  "none,'Y','N'";
  23. var CHECKBOX10    =  "none,1,0";
  24. var CHECKBOXNEG10 =  "none,-1,0";
  25. var CHECKBOXACCESS=  "none,Yes,No";
  26.  
  27. var STR_DIVIDER = "* *";
  28. var STR_ELEMENT_NAMES = STR_DIVIDER;
  29.  
  30. var DB_UNSUPPORTED_COLUMNS_ENUM_MAP = null;
  31.  
  32. var DEBUG_FILE = dw.getConfigurationPath() + "/SO_DEBUG.txt";
  33.  
  34. //--------------------------------------------------------------------
  35. // FUNCTION:
  36. //   createFormElementStrings
  37. //
  38. // DESCRIPTION:
  39. //   This function creates the form element strings that will be used
  40. //   to create the final form.
  41. //
  42. // ARGUMENTS:
  43. //   none
  44. //
  45. // RETURNS:
  46. //   nothing
  47. //--------------------------------------------------------------------
  48. function createFormElementStrings(rowInfoArr)
  49. {
  50.   var nRows = rowInfoArr.length, i,currRowInfoObj;
  51.   var fieldInfoObj, fieldType, fieldLabel, fieldVal;
  52.   var formElemObj, formElemStrArr = new Array(), formElemStr;
  53.  
  54.   for (i = 0; i < nRows; i++)
  55.   {
  56.     fieldType = "", fieldLabel = "";
  57.     
  58.     currRowInfoObj = rowInfoArr[i];
  59.     fieldInfoObj = currRowInfoObj.displayAs; 
  60.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  61.     fieldLabel = currRowInfoObj.label;    
  62.     fieldVal = fieldInfoObj.value;         
  63.     fieldType = fieldInfoObj.type;
  64.     
  65.     formElemObj = new Object();    
  66.     formElemObj.ElementName = fieldInfoObj.fieldName;
  67.     formElemObj.ElementType = fieldType.toLowerCase();
  68.     formElemObj.ElementValue = fieldVal;
  69.     formElemObj.ElementLabel = fieldLabel;
  70.     formElemObj.EqualToVal = "";
  71.     
  72.     if (fieldType == "checkBox")
  73.     {
  74.       formElemObj.ElementChecked = "";
  75.       if (fieldInfoObj.checked)
  76.       {
  77.         formElemObj.ElementChecked = "checked";
  78.       }
  79.     }
  80.     else if (fieldType == "text")
  81.     {
  82.       formElemObj.ElementValue = fieldInfoObj.text;
  83.     }
  84.     else if (fieldType == "dynamicCheckBox")
  85.     {  
  86.       formElemObj.ElementChecked = "";
  87.       if(fieldInfoObj.checkIf)
  88.       {
  89.         var selObj = new Object();
  90.         selObj.expression1 = dwscripts.encodeDynamicExpression(fieldInfoObj.checkIf); 
  91.         selObj.expression2 = dwscripts.encodeDynamicExpression(fieldInfoObj.equalTo); 
  92.         formElemObj.ElementChecked = extPart.getInsertString("", "DynamicCheckbox_attrib", selObj, "");
  93.       }
  94.     }
  95.     else if (fieldType == "menu")
  96.     {
  97.       var nOptions = fieldInfoObj.textArr.length;
  98.       var defaultSelected = fieldInfoObj.defaultSelected;
  99.       
  100.       if (!nOptions) 
  101.       {
  102.          var labelText = "[ " + MM.LABEL_Label + " ]";
  103.          fieldInfoObj.textArr = new Array(labelText, labelText);
  104.          fieldInfoObj.valArr   = new Array("menuitem1","menuitem2");
  105.          nOptions = 2;
  106.       }      
  107.       
  108.       formElemObj.OptionText = fieldInfoObj.textArr;
  109.       formElemObj.OptionValue = fieldInfoObj.valArr;
  110.  
  111.       var optionSelectedArr = new Array();
  112.       // This logic checks if the selected field is same as the value,
  113.       // if so marks it as selected, otherwise adds an empty string.
  114.       // this logic is required because all the arrays should be of same
  115.       // length for loop in edml file
  116.       for(var j = 0; j < nOptions; j++)
  117.       {
  118.         if(fieldInfoObj.valArr[j] && defaultSelected)
  119.         {
  120.           var selObj = new Object;
  121.           selObj.DefaultSelected = dwscripts.encodeDynamicExpression(defaultSelected);
  122.           if (   selObj.DefaultSelected.length > 1 && selObj.DefaultSelected.charAt(0) == "#" 
  123.               && selObj.DefaultSelected.charAt(selObj.DefaultSelected.length - 1) == "#" 
  124.              )
  125.           {
  126.             selObj.DefaultSelected = selObj.DefaultSelected.slice(1, 
  127.                                        selObj.DefaultSelected.length - 1);
  128.           }
  129.  
  130.           if (fieldInfoObj.valArr[j])
  131.           {
  132.             var tempItemValue = dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]);
  133.             // We need to strip the outer #'s if present
  134.             if (   tempItemValue.length > 1 && tempItemValue.charAt(0) == "#" 
  135.                 && tempItemValue.charAt(tempItemValue.length - 1) == "#" 
  136.                )
  137.             {
  138.               tempItemValue = tempItemValue.slice(1, tempItemValue.length - 1);
  139.             }
  140.             selObj.ItemValue = tempItemValue;
  141.           }
  142.           else
  143.           {
  144.             selObj.ItemValue = fieldInfoObj.valArr[j];
  145.           }
  146.  
  147.           var expr = extPart.getInsertString("", "Menu_OptionSelected", selObj, "");
  148.           optionSelectedArr.push(expr);
  149.         }
  150.         else
  151.         {
  152.           optionSelectedArr.push("");
  153.         }
  154.       }
  155.       formElemObj.OptionSelected = optionSelectedArr;  
  156.     }
  157.     else if (fieldType == "dynamicMenu")
  158.     {
  159.       var equalTo = fieldInfoObj.defaultSelected;    
  160.       formElemObj.DynOptionText = fieldInfoObj.textCol;
  161.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  162.  
  163.       if (equalTo)
  164.       {
  165.         var tempEqualTo = dwscripts.encodeDynamicExpression(equalTo);
  166.         // We need to strip the outer #'s if present
  167.         if (   tempEqualTo.length > 1 && tempEqualTo.charAt(0) == "#" 
  168.             && tempEqualTo.charAt(tempEqualTo.length - 1) == "#" 
  169.            )
  170.         {
  171.           tempEqualTo = tempEqualTo.slice(1, tempEqualTo.length - 1);
  172.         }
  173.         formElemObj.EqualToVal = tempEqualTo;
  174.       }
  175.       else
  176.       {
  177.         formElemObj.EqualToVal = equalTo;
  178.       }
  179.  
  180.       formElemObj.RecordsetName = fieldInfoObj.recordset;    
  181.     }
  182.     else if (fieldType == "radioGroup")
  183.     {
  184.       var nButtons = fieldInfoObj.labelArr.length;
  185.       var defaultChecked = fieldInfoObj.defaultChecked;
  186.       
  187.       if (!nButtons) 
  188.       {
  189.          var labelText = "[ " + MM.LABEL_Label + " ]";
  190.          fieldInfoObj.labelArr = new Array(labelText, labelText);
  191.          fieldInfoObj.valArr   = new Array("radiobutton1","radiobutton2");
  192.          nButtons = 2;
  193.       }
  194.       
  195.       formElemObj.FieldLabel = fieldInfoObj.labelArr;
  196.       formElemObj.FieldValue = fieldInfoObj.valArr;
  197.     
  198.       var fieldCheckedArr = new Array();
  199.       
  200.       // This logic checks if the checked field is same as the value,
  201.       // if so marks it as checked, otherwise adds an empty string.
  202.       // this logic is required because all the arrays should be of same
  203.       // length for a loop in edml file
  204.       for(j = 0;j < nButtons; j++)
  205.       {
  206.         if(fieldInfoObj.valArr[j] && defaultChecked)
  207.         {
  208.           var selObj = new Object;
  209.           selObj.DefaultChecked = dwscripts.encodeDynamicExpression(defaultChecked);
  210.           
  211.           if (fieldInfoObj.valArr[j])
  212.           {
  213.             var tempItemValue = dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]);
  214.             // We need to strip the outer #'s if present
  215.             if (   tempItemValue.length > 1 && tempItemValue.charAt(0) == "#" 
  216.                 && tempItemValue.charAt(tempItemValue.length - 1) == "#" 
  217.                )
  218.             {
  219.               tempItemValue = tempItemValue.slice(1, tempItemValue.length - 1);
  220.             }
  221.             selObj.ItemValue = tempItemValue;
  222.           }
  223.           else
  224.           {
  225.             selObj.ItemValue = fieldInfoObj.valArr[j];
  226.           }
  227.            
  228.           var expr = extPart.getInsertString("", "Radio_OptionChecked", selObj, "");
  229.           fieldCheckedArr.push(expr);
  230.         }
  231.         else
  232.         {
  233.           fieldCheckedArr.push("");
  234.         }
  235.       }
  236.       formElemObj.FieldChecked = fieldCheckedArr;       
  237.     }
  238.     else if (fieldType == "dynamicRadioGroup")
  239.     {
  240.       var equalTo = fieldInfoObj.defaultChecked;        
  241.       formElemObj.DynFieldName = fieldInfoObj.labelCol;
  242.       formElemObj.DynFieldValue = fieldInfoObj.valCol;
  243.  
  244.       if (equalTo)
  245.       {
  246.         var tempEqualTo = dwscripts.encodeDynamicExpression(equalTo);
  247.         // We need to strip the outer #'s if present
  248.         if (   tempEqualTo.length > 1 && tempEqualTo.charAt(0) == "#" 
  249.             && tempEqualTo.charAt(tempEqualTo.length - 1) == "#" 
  250.            )
  251.         {
  252.           tempEqualTo = tempEqualTo.slice(1, tempEqualTo.length - 1);
  253.         }
  254.         formElemObj.EqualToVal = tempEqualTo;
  255.       }
  256.       else
  257.       {
  258.         formElemObj.EqualToVal = equalTo;
  259.       }
  260.  
  261.       formElemObj.RecordsetName = fieldInfoObj.recordset;     
  262.     }
  263.     formElemStr = extPart.getInsertString("", "EditOp-FormElement", formElemObj, "");
  264.     formElemStrArr.push(formElemStr);
  265.   }
  266.   
  267.   return formElemStrArr;
  268. }
  269.  
  270.  
  271. //*-------------------------------------------------------------------
  272. // FUNCTION:
  273. //   wrapNamesWithSpaces
  274. //
  275. // DESCRIPTION:
  276. //   this fn is needed for SQL statements,
  277. //   names with spaces need brackets around them
  278. //
  279. // ARGUMENTS:
  280. //   nameStr - the name to wrap
  281. //
  282. // RETURNS:
  283. //   string - the wrapped name
  284. //--------------------------------------------------------------------
  285. function wrapNamesWithSpaces(nameStr){
  286.   var hasSpaces = ( nameStr.indexOf(" ") != -1 );
  287.   return (hasSpaces)? "[" + nameStr + "]" : nameStr;
  288.  
  289. }
  290.  
  291.  
  292. //*-------------------------------------------------------------------
  293. // FUNCTION:
  294. //   browseFile
  295. //
  296. // DESCRIPTION:
  297. //  Invokes dialog to allow user to select filename. Puts value in text input.
  298. //  The optional flag stripParameters will remove anything after a question
  299. //  mark if it is set to true
  300. //
  301. // ARGUMENTS:
  302. //   fieldToStoreURL 
  303. //   stripParameters - boolean flag to remove anything after a question
  304. //   mark
  305. //
  306. // RETURNS:
  307. //   string - the wrapped name
  308. //--------------------------------------------------------------------
  309. function browseFile(fieldToStoreURL, stripParameters) {
  310.   var fileName = "";
  311.   fileName = browseForFileURL();  //returns a local filename
  312.   if (stripParameters) {
  313.     var index = fileName.indexOf("?");
  314.     if (index != -1) {
  315.       fileName = fileName.substring(0,index);
  316.     }
  317.   }
  318.   if (fileName) fieldToStoreURL.value = fileName;
  319. }
  320.  
  321. //--------------------------------------------------------------------
  322. // FUNCTION:
  323. //   populateColumnGrid
  324. //
  325. // DESCRIPTION:
  326. //   This function is called by updateUI function.  It is responsible
  327. //   for populating the Column grid.
  328. //
  329. // ARGUMENTS:
  330. //   none
  331. //
  332. // RETURNS:
  333. //   nothing
  334. //--------------------------------------------------------------------
  335. function populateColumnGrid()
  336. {
  337.   // clear additional column list
  338.   // it lists columns that don't get populated in the grid, and needs to be cleared
  339.   updateAdditionalColumnList('clear'); 
  340.     
  341.     // if there are no tables, then clear grid
  342.   if ( !connectionHasBeenChosen() )
  343.   {
  344.     _ColumnNames.setAllRows(new Array(),new Array());
  345.     return;
  346.   }
  347.  
  348.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(_ConnectionName.getValue(), _TableName.getValue());
  349.   ColumnTypes = new Array();  // clear the column types map
  350.   var rowTextArr = new Array();
  351.   var rowValArr  = new Array();
  352.  
  353.   for (var i=0; i < colsAndTypes.length; i+=2)
  354.   {
  355.     ColumnTypes[colsAndTypes[i]] = colsAndTypes[i+1];
  356.     
  357.     if (EDIT_OP_TYPE == "Update") 
  358.     {
  359.       rowInfo = getRowTextAndValue(colsAndTypes[i], colsAndTypes[i+1], _RecordsetName.getValue(), _UniqueKeyColumn.getValue());
  360.     } 
  361.     else 
  362.     {  
  363.       // if Insert (and recordset menu does not exist)
  364.       rowInfo = getRowTextAndValue(colsAndTypes[i],colsAndTypes[i+1]);
  365.     }
  366.     rowTextArr.push(rowInfo[0]);
  367.     rowValArr.push(rowInfo[1]);
  368.   }
  369.  
  370.   _ColumnNames.setAllRows(rowTextArr, rowValArr);
  371.     
  372.   // clear global field names array (used to check for dupe field names)
  373.   STR_ELEMENT_NAMES = STR_DIVIDER;    
  374. }
  375.  
  376. //--------------------------------------------------------------------
  377. // FUNCTION:
  378. //   checkForUnsupportedColumnTypes
  379. //
  380. // DESCRIPTION:
  381. //   This function checks if all the columns are supported or not,
  382. //   displaying a message
  383. //
  384. // ARGUMENTS:
  385. //   Boolean - to display alert message or not
  386. //
  387. // RETURNS:
  388. //   Nothing
  389. //--------------------------------------------------------------------
  390. function checkForUnsupportedColumnTypes(displayMsg)
  391. {   
  392.   // check for the colTypes to make sure we support them, if not
  393.   // the flow is that they don't appear in the form fields grids,
  394.   // But we do display a message saying that they are not displayed,
  395.   // but the user can add them manually by clicking on the + button...
  396.   var unsupportedColTypes = new Array();
  397.   var unsupportedColNames = new Array();
  398.   
  399.   for(var i = 0; i < _ColumnNames.valueList.length; i++)
  400.   {
  401.     var rowInfoObj = _ColumnNames.valueList[i];
  402.     if (rowInfoObj && rowInfoObj.colType)
  403.     {
  404.       if (!isColTypeSupported(rowInfoObj.colType))
  405.       {
  406.         unsupportedColTypes.push(rowInfoObj.colType);
  407.         unsupportedColNames.push(rowInfoObj);
  408.       }
  409.     }
  410.   }  
  411.   
  412.   if (unsupportedColTypes.length && unsupportedColNames.length)
  413.   {
  414.     if(displayMsg)
  415.     {
  416.       // Note: we use a setTimeout to alert the warning message to fix Mac bug
  417.       //   #58368. Before this dialog is shown, the MM:Treecontrol is updated.
  418.       //   After the update from the JS side is complete, we put up this alert.
  419.       //   However, it appears the the updates to MM:Treecontrol force the dialog 
  420.       //   to refresh, and this refresh continues after the alert dialog is up.
  421.       //   The refresh takes the focus from the alert. Dreamweaver is then in
  422.       //   a frozen state where the SB dialog has focus and the alert dialog is
  423.       //   stuck behind it. By using setTimeout, the alert is not shown until the
  424.       //   dialog is completely refreshed (we hope).
  425.       var alertScript = "alert('" 
  426.                       + dwscripts.sprintf(MM.Msg_UnsupportedColumnsInTable, unsupportedColTypes)
  427.                       + "')";
  428.       setTimeout(alertScript, 250);
  429.     }
  430.     for(var i = 0; i < unsupportedColNames.length; i++)
  431.     {
  432.       // select the row that is to be deleted...
  433.       _ColumnNames.pickRowValue(unsupportedColNames[i]);
  434.       deleteGridRow();    
  435.     }
  436.   }
  437.  
  438. }
  439.  
  440. //--------------------------------------------------------------------
  441. // FUNCTION:
  442. //   isColTypeSupported
  443. //
  444. // DESCRIPTION:
  445. //   This function returns if the colType is supported by UD or not.
  446. //
  447. // ARGUMENTS:
  448. //   colType - string - column type for update
  449. //
  450. // RETURNS:
  451. //   boolean
  452. //--------------------------------------------------------------------
  453. function isColTypeSupported(colType)
  454. {
  455.   var retVal = true;
  456.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  457.   {
  458.     buildUnsupportedColumnsEnum();
  459.   }
  460.   
  461.   var unsupportedCol = DB_UNSUPPORTED_COLUMNS_ENUM_MAP[colType.toLowerCase()]  
  462.   if (unsupportedCol)
  463.   {
  464.     // col is not supported,,,
  465.     retVal = false;
  466.   }
  467.   else
  468.   {
  469.     retVal = true;
  470.   }   
  471.   
  472.   return retVal;  
  473. }
  474.  
  475. //--------------------------------------------------------------------
  476. // FUNCTION:
  477. //   buildUnsupportedColumnsEnum
  478. //
  479. // DESCRIPTION:
  480. //   This function returns if the colType is supported by UD or not.
  481. //
  482. // ARGUMENTS:
  483. //   colType - string - column type for update
  484. //
  485. // RETURNS:
  486. //   boolean
  487. //--------------------------------------------------------------------
  488. function buildUnsupportedColumnsEnum()
  489. {
  490.     if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  491.     {
  492.       // TODO: read in from a configuration file
  493.       var a = new Array();
  494.       a["binary"] = 128; 
  495.       a["varbinary"] = 204;
  496.       a["longvarbinary"] = 204; 
  497.       a["longbinary"] = 205; // matched to longvarbinary
  498.                 
  499.       //oracle
  500.       a["raw"]  = 204;// Match it to Binary
  501.       a["nclob"]  = 204;//Match it to Binary
  502.       a["bfile"]  = 204;//Match it to Binary
  503.       a["ref cursor"] = 900; //Arbitrary ID Val
  504.       a["refcursor"] = 900;
  505.       // SQL Server 7
  506.       a["image"]  =  204 ;// binary
  507.       
  508.       DB_UNSUPPORTED_COLUMNS_ENUM_MAP = a;
  509.     }
  510. }
  511.  
  512.  
  513. //--------------------------------------------------------------------
  514. // FUNCTION:
  515. //   getRowTextAndValue
  516. //
  517. // DESCRIPTION:
  518. //   This function returns the information for a row in the column table.
  519. //
  520. // ARGUMENTS:
  521. //   colName - string - column name
  522. //   colType - string - column type
  523. //   rsName  - string - (optional) recordset name, only needed for update
  524. //   uniqueColName - string - (optional) Unique Key Column, only needed
  525. //                            for update
  526. //
  527. // RETURNS:
  528. //   array of 2 values
  529. //--------------------------------------------------------------------
  530. function getRowTextAndValue(colName, colType, rsName, uniqueColName)
  531. {
  532.   var retVal = new Array(2);
  533.   var colFieldType = "", colSubmitType = "", colSubmitName = "";
  534.   
  535.   var colLabel = getLabelFromColumnName(colName);
  536.   
  537.   var fieldName = getElementNameFromColumnName(colName);
  538.   // if update, the unique key column should be a static text...
  539.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  540.   {
  541.     colFieldType = STATICTEXT;
  542.   }
  543.   else
  544.   {
  545.     // default to password display type if "password" appears in field name
  546.     if (colName.toLowerCase().indexOf(PASSWORD) != -1)
  547.     {
  548.       colFieldType = PASSWORDFIELD;
  549.     }
  550.     else
  551.     {
  552.       colFieldType = getFieldTypeFromColumnType(colType);
  553.     }
  554.   }
  555.   
  556.   var colSubmitType = getSubmitTypeFromColumnType(colType);
  557.   var colSubmitName = getSubmitNameFromSubmitType(colSubmitType);   
  558.  
  559.   var colDisplayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  560.   
  561.   // disable the _SubmitAs field if it is for the Primary Key column
  562.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  563.   {
  564.     UniqueColSubmitAs = colSubmitType;
  565.     colSubmitType = "";  
  566.     colSubmitName = "";
  567.     toggleSubmitAs(false); // enable or disable Submit As Menu
  568.     toggleLabelVisibility(colDisplayAs);    // enable or disable Label textfield
  569.   }
  570.   
  571.   var rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitName;
  572.  
  573.   var rowValObj = new Object();  
  574.   rowValObj.column = colName;
  575.   rowValObj.label = colLabel;
  576.   rowValObj.displayAs = colDisplayAs;
  577.   rowValObj.submitAs = colSubmitType;
  578.   rowValObj.fieldName = fieldName;
  579.   rowValObj.defaultStr = "";
  580.   rowValObj.passwordStr = "";
  581.   rowValObj.colType = colType;
  582.   
  583.   // populate storage object with any default values
  584.   if (EDIT_OP_TYPE == "Update" && rowValObj.displayAs.type != "passwordField")
  585.   {
  586.     var rs = (rsName)?rsName:_RecordsetName.getValue();
  587.     rowValObj = populateFormFieldStorageType(rowValObj,rs,colName);
  588.   }
  589.  
  590.   retVal[0] = rowText;
  591.   retVal[1] = rowValObj;
  592.             
  593.   return retVal;
  594. }
  595.  
  596. //--------------------------------------------------------------------
  597. // FUNCTION:
  598. //   getLabelFromColumnName
  599. //
  600. // DESCRIPTION:
  601. //
  602. // ARGUMENTS:
  603. //
  604. // RETURNS:
  605. //   Nothing
  606. //--------------------------------------------------------------------
  607. function getLabelFromColumnName(colName)
  608. {
  609.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  610. }
  611.  
  612. //--------------------------------------------------------------------
  613. // FUNCTION:
  614. //   getElementNameFromColumnName
  615. //
  616. // DESCRIPTION:
  617. //
  618. // ARGUMENTS:
  619. //   col - string - the column name to create an element name from
  620. //
  621. // RETURNS:
  622. //   string -  the element name
  623. //--------------------------------------------------------------------
  624. function getElementNameFromColumnName(col)
  625. {
  626.   var elemName = col;
  627.   var counter = 2;
  628.   var divider = STR_DIVIDER;
  629.  
  630.   // replace spaces with underscores
  631.   elemName = elemName.replace(/ /g, "_");
  632.   
  633.   // strip out all characters that are not alpha-numeric, or underscores
  634.   elemName = elemName.replace(/[^a-zA-Z_0-9]/g, "");
  635.   
  636.   // don't allow the first character to be numeric
  637.   while (parseInt(elemName.charAt(0)) &&
  638.          parseInt(elemName.charAt(0)) == elemName.charAt(0) )
  639.   {
  640.     elemName = elemName.substring(1);
  641.   }
  642.  
  643.   // in the unlikely case that no characters are left after the above,
  644.   // then name element generically as "element"
  645.   if (elemName.length == 0)
  646.   {
  647.     elemName = MM.LABEL_Element;
  648.   }
  649.  
  650.   // ensure that name is not a dupe
  651.   var tempName = elemName; 
  652.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != -1)
  653.   {
  654.     elemName = tempName + counter++;
  655.   }
  656.  
  657.   // add name to global names list
  658.   STR_ELEMENT_NAMES += elemName + divider;
  659.  
  660.   return elemName;
  661. }
  662.  
  663. //--------------------------------------------------------------------
  664. // FUNCTION:
  665. //   getFieldTypeFromColumnType
  666. //
  667. // DESCRIPTION:
  668. //   This function returns the field type based on the given column type
  669. //
  670. // ARGUMENTS:
  671. //   colType - string - the column type returned from MMDB
  672. //
  673. // RETURNS:
  674. //   Nothing
  675. //--------------------------------------------------------------------
  676. function getFieldTypeFromColumnType(colType)
  677. {
  678.   return (dwscripts.isBooleanDBColumnType(colType)) ? CHECKBOX : TEXTFIELD;
  679. }
  680.  
  681. //--------------------------------------------------------------------
  682. // FUNCTION:
  683. //   getSubmitTypeFromColumnType
  684. //
  685. // DESCRIPTION:
  686. //   This function is called when the grid is populated, to choose a 
  687. //   submit type based on the column type
  688. //
  689. //   Note: this function is used during initial population only.
  690. //         getSubmitTypeBasedOnElementType() is used when the 
  691. //         element type is changed
  692. //
  693. // ARGUMENTS:
  694. //   colType - string - the column type returned from MMDB
  695. //
  696. // RETURNS:
  697. //   nothing
  698. //--------------------------------------------------------------------
  699. function getSubmitTypeFromColumnType(colType)
  700. {
  701.   var retVal = "";
  702.   var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  703.   var colIsDate    = dwscripts.isDateDBColumnType(colType);
  704.   var colIsBoolean = dwscripts.isBooleanDBColumnType(colType);
  705.   // added condition for currency...skarra
  706.   var colIsCurrency = dwscripts.isCurrencyDBColumnType(colType);
  707.  
  708.   if ( colIsNumeric )
  709.   {
  710.     retVal = (colIsBoolean) ? CHECKBOX10 : NUMERIC;
  711.   }
  712.   else if ( colIsDate )
  713.   {
  714.     retVal = DATE;
  715.   }
  716.   else if (colIsCurrency)
  717.   {
  718.     retVal = NUMERIC;
  719.   }
  720.   else
  721.   { // if text-based
  722.     retVal = (colIsBoolean) ? CHECKBOXYN : TEXT;
  723.   }
  724.   
  725.   return retVal;
  726. }
  727.  
  728. //--------------------------------------------------------------------
  729. // FUNCTION:
  730. //   getSubmitTypeBasedOnElementType
  731. //
  732. // DESCRIPTION:
  733. //   Called when the element type is changed, to update the submit type
  734. //
  735. // ARGUMENTS:
  736. //   submitType - string - the current submit type
  737. //   elemType - string - the current element type
  738. //   colType - string - the current column type
  739. //
  740. // RETURNS:
  741. //   Nothing
  742. //--------------------------------------------------------------------
  743. function getSubmitTypeBasedOnElementType(submitType, elemType, colType)
  744. {
  745.   var newSubmitType = submitType;
  746.   
  747.   // don't bother if conection hasn't been chosen
  748.   if ( connectionHasBeenChosen() )
  749.   {
  750.     var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  751.     var colIsDate    = dwscripts.isDateDBColumnType(colType);
  752.  
  753.     if ( elemType == CHECKBOX )
  754.     { 
  755.       // if display element is a checkbox
  756.       if (colIsNumeric)
  757.       {
  758.         newSubmitType = CHECKBOX10;
  759.       }
  760.       else
  761.       {
  762.         newSubmitType = CHECKBOXYN;
  763.       }
  764.     }
  765.     else
  766.     { // display type does not equal checkbox
  767.  
  768.       // if submit type is currently a checkbox type,
  769.       // then change it back to the most appropriate
  770.       // non-checkbox type
  771.  
  772.       if (submitType==CHECKBOXYN    || submitType==CHECKBOX10 ||
  773.           submitType==CHECKBOXNEG10 || submitType == CHECKBOXACCESS)
  774.       {
  775.         if (colIsNumeric)
  776.         {
  777.           newSubmitType = NUMERIC;
  778.         }
  779.         else if (colIsDate)
  780.         {
  781.           newSubmitType = DATE;
  782.         }
  783.         else
  784.         {
  785.           newSubmitType = TEXT;
  786.         }
  787.       }
  788.     }
  789.   }
  790.   
  791.   return newSubmitType;
  792. }
  793.  
  794.  
  795. //--------------------------------------------------------------------
  796. // FUNCTION:
  797. //   getSubmitNameFromSubmitType
  798. //
  799. // DESCRIPTION:
  800. //   Returns the display string that should be used for the given
  801. //   submit as type
  802. //
  803. // ARGUMENTS:
  804. //   submitType - string - the comma separated list of submit values
  805. //
  806. // RETURNS:
  807. //   string
  808. //--------------------------------------------------------------------
  809. function getSubmitNameFromSubmitType(submitType)
  810. {
  811.   var submitTypeLabels = _SubmitAs.get('all');
  812.   var submitTypeValues = _SubmitAs.getValue('all');
  813.   
  814.   var submitName = "";
  815.   
  816.   var index = dwscripts.findInArray(submitTypeValues, submitType);
  817.   if (index >= 0)
  818.   {
  819.     submitName = submitTypeLabels[index];
  820.   }
  821.   else
  822.   {
  823.     submitName = submitTypeLabels[0];
  824.   }
  825.   
  826.   return submitName;
  827. }
  828.  
  829. //--------------------------------------------------------------------
  830. // FUNCTION:
  831. //   getFormFieldStorageObjectFromFormFieldType
  832. //
  833. // DESCRIPTION:
  834. //   This function returns a field storage object, based on the 
  835. //   given field type.
  836. //
  837. // ARGUMENTS:
  838. //   fieldType - string - the field type selected in the UI
  839. //
  840. // RETURNS:
  841. //   object
  842. //--------------------------------------------------------------------
  843. function getFormFieldStorageObjectFromFormFieldType(fieldType)
  844. {
  845.   var retObj = "";
  846.  
  847.   if (fieldType == STATICTEXT)
  848.   {
  849.     retObj = new eoText();
  850.   }
  851.   else if (fieldType == TEXTFIELD)
  852.   {
  853.     retObj = new eoTextField();
  854.   }
  855.   else if (fieldType == HIDDENFIELD)
  856.   {
  857.     retObj = new eoHiddenField();
  858.   }
  859.   else if (fieldType == PASSWORDFIELD)
  860.   {
  861.     retObj = new eoPasswordField();
  862.   }
  863.   else if (fieldType == FILEFIELD)
  864.   {
  865.     retObj = new eoFileField();
  866.   }
  867.   else if (fieldType == TEXTAREA)
  868.   {
  869.     retObj = new eoTextArea();
  870.   }
  871.   else if (fieldType == MENU)
  872.   {
  873.     retObj = new eoMenu();
  874.   }
  875.   else if (fieldType == RADIOGROUP)
  876.   {
  877.     retObj = new eoRadioGroup();
  878.   }
  879.   else if (fieldType == CHECKBOX)
  880.   {
  881.     retObj = (EDIT_OP_TYPE == "Insert")?new eoCheckBox():new eoDynamicCheckBox();
  882.   } 
  883.  
  884.   return retObj;
  885. }
  886.  
  887. //--------------------------------------------------------------------
  888. // FUNCTION:
  889. //   displayGridFieldValues
  890. //
  891. // DESCRIPTION:
  892. //   This function is called when the user clicks on a new row in the 
  893. //   grid, changes the values of the UI fields to display the correct
  894. //   information
  895. //
  896. // ARGUMENTS:
  897. //   None
  898. //
  899. // RETURNS:
  900. //   Nothing
  901. //--------------------------------------------------------------------
  902. function displayGridFieldValues()
  903.   // don't bother if grid is empty -- needed because this fn is also
  904.   // called when the connection or table changes
  905.   if (_ColumnNames.list.length == 0)
  906.   {
  907.     _ElementLabel.value = "";
  908.   }
  909.   else
  910.   {
  911.     var currRowText = _ColumnNames.getRow();
  912.     var currRowVal  = _ColumnNames.getRowValue();
  913.     
  914.     var rowTextTokens = getTokens(currRowText,"|");
  915.  
  916.     // TODO: this should be taken from the record, not the display
  917.     _ElementLabel.value = rowTextTokens[1]; // update label field
  918.     _DisplayAs.pickValue(rowTextTokens[2]); // update display menu
  919.  
  920.     // change UI at bottom of dialog, if relevent
  921.     // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  922.     showDifferentParams(); 
  923.  
  924.     if (dwscripts.findDOMObject("SubmitAs")) 
  925.     {
  926.       _SubmitAs.pickValue(currRowVal.submitAs); // update submit menu
  927.     }
  928.  
  929.     // fill in form parameters at bottom of UI
  930.     // note that in the case of radio or menu, there is nothing to fill in
  931.     switch (currRowVal.displayAs.type)
  932.     {
  933.     case "text":
  934.       dwscripts.findDOMObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  935.       break;
  936.     case "textArea":
  937.     case "textField":
  938.     case "hiddenField":
  939.     case "fileField":
  940.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  941.       break;
  942.     case "passwordField":
  943.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.passwordStr;
  944.       break;
  945.     case "checkBox": 
  946.       // note: dwscripts.findDOMObject doesn't work with radios, so manual references are needed
  947.       var InitialStateRadios = document.forms[0].InitialState;
  948.       if ( currRowVal.displayAs.checked.toString() == "true")
  949.       {
  950.         InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  951.       }
  952.       else
  953.       {
  954.         InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  955.       }
  956.       break;
  957.  
  958.     case "dynamicCheckBox":
  959.       dwscripts.findDOMObject("CheckIf").value = currRowVal.displayAs.checkIf;
  960.       dwscripts.findDOMObject("EqualTo").value = currRowVal.displayAs.equalTo;
  961.       break;
  962.  
  963.     case "default":
  964.       break; 
  965.     }
  966.   }
  967. }
  968.  
  969. //--------------------------------------------------------------------
  970. // FUNCTION:
  971. //   showDifferentParams
  972. //
  973. // DESCRIPTION:
  974. //   This function shows form field specific parameters at the bottom
  975. //   of the dialog for instance, shows "Menu Properties" button for 
  976. //   menu, value field for textfield, etc
  977. //
  978. // ARGUMENTS:
  979. //   displayDefaultStr - Column Name
  980. //
  981. // RETURNS:
  982. //   Nothing
  983. //--------------------------------------------------------------------
  984. function showDifferentParams(displayDefaultStr)
  985. {
  986.   // don't bother if connection has not been chosen
  987.   if ( connectionHasBeenChosen() )
  988.   {
  989.     //EnableDisableUpDownBtns();
  990.     
  991.     //EnableDisableAddDelBtns();
  992.     
  993.     var displayAs = _DisplayAs.getValue()?_DisplayAs.getValue():"none";
  994.     var tables = domUIPieces.getElementsByTagName("TABLE"), param, i;
  995.     var mmParamsTag = document.getElementsByTagName("mmParams").item(0);
  996.  
  997.     var rowInfoObj = _ColumnNames.getRowValue();
  998.     if (EDIT_OP_TYPE == "Update" && rowInfoObj.fieldName == _UniqueKeyColumn.getValue())
  999.     {
  1000.       toggleSubmitAs(false);
  1001.     }
  1002.     else
  1003.     {
  1004.       toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  1005.       toggleLabelVisibility(displayAs);    // enable or disable Label textfield
  1006.     }
  1007.  
  1008.     if (displayAs == TEXTFIELD || displayAs == TEXTAREA || displayAs == HIDDENFIELD ||
  1009.       displayAs == PASSWORDFIELD || displayAs == FILEFIELD)
  1010.     {
  1011.       param = "textField";
  1012.     }
  1013.     else if (displayAs == STATICTEXT)
  1014.     {
  1015.       param = "text";
  1016.     }
  1017.     else if (displayAs == RADIOGROUP)
  1018.     {
  1019.       param = "radio";
  1020.     }
  1021.     else if (displayAs == MENU)
  1022.     {
  1023.       param = "menu";
  1024.     }
  1025.     else if (displayAs == CHECKBOX)
  1026.     {
  1027.       param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  1028.     }
  1029.     else if (displayAs == "none")
  1030.     {
  1031.       param = "none";
  1032.     }
  1033.  
  1034.     for (i=0;i<tables.length;i++)
  1035.     {
  1036.       if (tables[i].name && tables[i].name == param)
  1037.       {
  1038.         mmParamsTag.innerHTML = tables[i].innerHTML;
  1039.         
  1040.         // NOTE: This is call is very expensize.  It causes the entire dialog to be
  1041.         //       repaginated.  This function is called as the user clicks on different
  1042.         //       items in the columns tree control, so we need this to be quick.
  1043.         //       Instead, we will adjust the size of the dialog to be large enough
  1044.         //       to accomodate all the controls.
  1045.         
  1046.         // resize window to contents - otherwise top of dialog is clipped (added as bugfix) 
  1047.         //window.resizeToContents(); 
  1048.         
  1049.         break;
  1050.       }
  1051.     }
  1052.     // if display as equals text, text area, or text field, and the display as menu has
  1053.     // just been changed, then display the default text for this column
  1054.     if (displayDefaultStr)
  1055.     {
  1056.       var rowInfoObj = _ColumnNames.getRowValue();
  1057.       var defaultStr = _ColumnNames.getRowValue().defaultStr;
  1058.       var passwordStr = _ColumnNames.getRowValue().passwordStr;
  1059.       if ( displayAs == TEXTFIELD || displayAs == TEXTAREA ||
  1060.         displayAs == HIDDENFIELD || displayAs == FILEFIELD )
  1061.       {
  1062.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  1063.       }
  1064.       else if ( displayAs == PASSWORDFIELD )
  1065.       {
  1066.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = passwordStr;    // set UI
  1067.       }
  1068.       else if ( displayAs == STATICTEXT )
  1069.       {
  1070.         dwscripts.findDOMObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  1071.       }
  1072.       else if ( param == "dynamicCheckBox" )
  1073.       {
  1074.         dwscripts.findDOMObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  1075.       }
  1076.     }
  1077.   }
  1078. }
  1079.  
  1080. //--------------------------------------------------------------------
  1081. // FUNCTION:
  1082. //   addGridRow
  1083. //
  1084. // DESCRIPTION:
  1085. //   This function is called if there are columns not already 
  1086. //   displayed in the grid pop up the "Add Columns" dialog, and allow
  1087. //   the user to add them
  1088. //
  1089. // ARGUMENTS:
  1090. //   None
  1091. //
  1092. // RETURNS:
  1093. //   Nothing
  1094. //--------------------------------------------------------------------
  1095. function addGridRow()
  1096. {
  1097.   // check to see if there are columns to add first
  1098.   if (ColumnsToAdd.length == 0)
  1099.   {
  1100.     alert(MM.MSG_NoMoreColumnsToAdd);
  1101.     return;
  1102.   }
  1103.   var addedCols = dwscripts.callCommand("Add Column.htm", ColumnsToAdd);
  1104.   if (!addedCols) return; // user clicked Cancel
  1105.   var nCols = addedCols.length,i, currCol, rowInfoArr;
  1106.  
  1107.   for (i=0;i<nCols;i++)
  1108.   {
  1109.     currCol = addedCols[i];
  1110.     rowInfoArr = getRowTextAndValue(currCol,ColumnTypes[currCol]);
  1111.     _ColumnNames.addRow(rowInfoArr[0],rowInfoArr[1]);
  1112.     updateAdditionalColumnList('del',currCol);
  1113.   }
  1114. }
  1115.  
  1116. //--------------------------------------------------------------------
  1117. // FUNCTION:
  1118. //   deleteGridRow
  1119. //
  1120. // DESCRIPTION:
  1121. //   This function is called when the user clicks the "-" image button
  1122. //
  1123. // ARGUMENTS:
  1124. //  None
  1125. //
  1126. // RETURNS:
  1127. //   Nothing
  1128. //--------------------------------------------------------------------
  1129. function deleteGridRow()
  1130. {
  1131.   var currRow = _ColumnNames.getRow();
  1132.   var currCol = currRow.substring(0,currRow.indexOf("|") );
  1133.   var nRows = _ColumnNames.list.length;
  1134.  
  1135.   if (nRows > 1)
  1136.   {
  1137.     updateAdditionalColumnList('add',currCol);
  1138.     _ColumnNames.delRow();
  1139.     displayGridFieldValues(); 
  1140.   }
  1141.   else
  1142.   {
  1143.     alert(MM.MSG_NeedOneColumnInList);
  1144.   }
  1145. }
  1146.  
  1147. //--------------------------------------------------------------------
  1148. // FUNCTION:
  1149. //   updateGridRow
  1150. //
  1151. // DESCRIPTION:
  1152. //   This function is called whenever the label, submitAs, or displayAs
  1153. //   fields are edited updates both the actual text display in the grid, 
  1154. //   and the object that stores the information about the display
  1155. //
  1156. // ARGUMENTS:
  1157. //   whichColumn: the parameter which has been edited -- displayAs, 
  1158. //   submitAs, or label
  1159. //
  1160. // RETURNS:
  1161. //   Nothing
  1162. //--------------------------------------------------------------------
  1163. function updateGridRow(whichColumn)
  1164. {
  1165.   // check that connection has been chosen before proceeding
  1166.   if ( !connectionHasBeenChosen() )
  1167.   {
  1168.     alert( MM.MSG_NoDataSourceSelected );
  1169.     // _DisplayAs.setIndex(0); // set display menu back to first item
  1170.     return;
  1171.   }
  1172.  
  1173.   var currRowObj  = _ColumnNames.getRowValue();
  1174.   var currRowText = _ColumnNames.getRow();
  1175.   var currColName = currRowText.substring(  0,currRowText.indexOf("|")  );
  1176.  
  1177.   // update grid row text
  1178.   var newRowText = currColName + "|" + _ElementLabel.value + "|" + _DisplayAs.get() + "|"; 
  1179.   newRowText += (dwscripts.findDOMObject("SubmitAs")) ? _SubmitAs.get() : "";
  1180.   _ColumnNames.setRow(newRowText);
  1181.  
  1182.   // update object that stores information about grid row
  1183.   // this object is stored in a value attribute of the Grid object
  1184.   // these objects are stored in an array: GridObj.valueList
  1185.  
  1186.   switch (whichColumn)
  1187.   {
  1188.   case "label":
  1189.     currRowObj.label = _ElementLabel.value;
  1190.     break;
  1191.  
  1192.   case "submitAs":
  1193.     currRowObj.submitAs = _SubmitAs.getValue();
  1194.     break;
  1195.  
  1196.   case "displayAs": 
  1197.     currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(_DisplayAs.getValue());
  1198.     // need to update submit property, because changing displayAs menu can
  1199.     // auto-change submit type
  1200.     if ( dwscripts.findDOMObject("SubmitAs") )
  1201.     {
  1202.       currRowObj.submitAs = _SubmitAs.getValue();
  1203.     }
  1204.  
  1205.     var defaultStr = currRowObj.defaultStr;
  1206.     var passwordStr = currRowObj.passwordStr;
  1207.     var fieldType = currRowObj.displayAs.type;
  1208.  
  1209.     if ( fieldType == "textField"  || fieldType == "hiddenField" || 
  1210.       fieldType == "fileField"  ||  fieldType == "textArea" )
  1211.     {
  1212.       currRowObj.displayAs.value = defaultStr;
  1213.     }
  1214.     else if ( fieldType == "passwordField")
  1215.     {
  1216.       currRowObj.displayAs.value = passwordStr;          
  1217.     }
  1218.     else if ( fieldType == "text")
  1219.     {
  1220.       currRowObj.displayAs.text = defaultStr;
  1221.     }
  1222.     else if ( fieldType == "menu")
  1223.     {
  1224.       currRowObj.displayAs.defaultSelected = defaultStr;
  1225.     }
  1226.     else if ( fieldType == "radioGroup")
  1227.     {
  1228.       currRowObj.displayAs.defaultChecked = defaultStr;
  1229.     }
  1230.     else if (fieldType == "dynamicCheckBox")
  1231.     {
  1232.       currRowObj.displayAs.checkIf = defaultStr;
  1233.     }
  1234.     break;
  1235.  
  1236.   default:
  1237.     break;
  1238.   }
  1239. }
  1240.  
  1241. //--------------------------------------------------------------------
  1242. // FUNCTION:
  1243. //   popUpFormFieldPropertiesDialog
  1244. //
  1245. // DESCRIPTION:
  1246. //   It pops up the Radio or Menu Properties dialog, and passes in the 
  1247. //   current menu/radio storage object so that the dialog can be 
  1248. //   initialized correctly
  1249. //
  1250. // ARGUMENTS:
  1251. //   whichOne - String that can be "Radio" or "Menu"
  1252. //
  1253. // RETURNS:
  1254. //   Nothing
  1255. //--------------------------------------------------------------------
  1256. function popUpFormFieldPropertiesDialog(whichOne)
  1257. {
  1258.   var commandFileName = "ServerObject-" + whichOne + "Props.htm";
  1259.   var rowObj = _ColumnNames.getRowValue();
  1260.   var fieldInfoObj = dwscripts.callCommand(commandFileName,rowObj.displayAs)
  1261.  
  1262.  
  1263.   // note: use the "type" property on the menuInfoObj to see which
  1264.     // type of object was returned
  1265.     if (fieldInfoObj)
  1266.   {
  1267.     rowObj.displayAs = fieldInfoObj;
  1268.   }
  1269. }
  1270.  
  1271. //--------------------------------------------------------------------
  1272. // FUNCTION:
  1273. //   updateAdditionalColumnList
  1274. //
  1275. // DESCRIPTION:
  1276. //   The + button calls up an Add Columns dialog, allowing
  1277. //   the user to add additional columns to the list. When the Add Columns
  1278. //   dialog is called, it is populated with the "additional columns list".
  1279. //   This list is updated when a user adds or deletes a column from the UI.
  1280. //
  1281. // ARGUMENTS:
  1282. //   action - Action argument that can Add, Del or Clear
  1283. //   col    - Column
  1284. //
  1285. // RETURNS:
  1286. //   Nothing
  1287. //--------------------------------------------------------------------
  1288. function updateAdditionalColumnList(action, col)
  1289. {
  1290.   if (action == 'add')
  1291.   {
  1292.     ColumnsToAdd.push(col);
  1293.   }
  1294.   else if ( action == 'clear')
  1295.   {
  1296.     ColumnsToAdd = new Array();
  1297.   }
  1298.   else
  1299.   { // delete an item from additional column list
  1300.     for (var i=0; i < ColumnsToAdd.length; i++)
  1301.     {
  1302.       if (ColumnsToAdd[i] == col)
  1303.       {
  1304.         ColumnsToAdd.splice(i,1);
  1305.         break;
  1306.       }
  1307.     }
  1308.   }
  1309. }
  1310.  
  1311. //--------------------------------------------------------------------
  1312. // FUNCTION:
  1313. //   connectionHasBeenChosen
  1314. //
  1315. // DESCRIPTION:
  1316. //   This function is called when the grid is populated, to choose a 
  1317. //   submit type based on the column type
  1318. //
  1319. // ARGUMENTS:
  1320. //   None
  1321. //
  1322. // RETURNS:
  1323. //   Nothing
  1324. //--------------------------------------------------------------------
  1325. function connectionHasBeenChosen()
  1326. {
  1327.   return (_ConnectionName.getValue());
  1328. }
  1329.  
  1330. /*
  1331. //--------------------------------------------------------------------
  1332. // FUNCTION:
  1333. //   setFieldsAndColumns
  1334. //
  1335. // DESCRIPTION:
  1336. //   This function is called when the grid is populated, to choose a 
  1337. //   submit type based on the column type
  1338. //
  1339. // ARGUMENTS:
  1340. //   paramObj - 
  1341. //
  1342. // RETURNS:
  1343. //   Nothing
  1344. //--------------------------------------------------------------------
  1345. function setFieldsAndColumns(paramObj) {
  1346.   var colInfoObjs = _ColumnNames.valueList, nCols = colInfoObjs.length, i, currObj;
  1347.   var fieldsStr = "",columnsStr = "", submitType;
  1348.   
  1349.   // create mini-lookup table
  1350.   var lookupTable = new Object();
  1351.   lookupTable[TEXT]          = "',none,''";
  1352.   lookupTable[NUMERIC]       = "none,none,NULL";
  1353.   lookupTable[DATE]          = "',none,NULL";
  1354.   lookupTable[DATEMSACCESS]  = "#,none,NULL";
  1355.   lookupTable[CHECKBOXYN]    = "none,'Y','N'";
  1356.   lookupTable[CHECKBOX10]    = "none,1,0";
  1357.   lookupTable[CHECKBOXNEG10] = "none,-1,0";
  1358.   lookupTable[CHECKBOXACCESS]= "none,Yes,No";
  1359.   
  1360.   for (i=0;i<nCols;i++)
  1361.   {
  1362.     currObj = colInfoObjs[i];
  1363.     if (currObj.displayAs.type != "text"){ // if a form element
  1364.       submitType = currObj.submitAs;  
  1365.       fieldsStr += currObj.fieldName + "|value|";
  1366.       columnsStr += wrapNamesWithSpaces(currObj.column) + "|" + lookupTable[submitType] + "|";
  1367.     }
  1368.   }
  1369.   
  1370.   // remove last separators
  1371.   fieldsStr = fieldsStr.substring(0,fieldsStr.length-1);
  1372.   columnsStr = columnsStr.substring(0,columnsStr.length-1);
  1373.   
  1374.   if (dw.getDocumentDOM() != null && 
  1375.       dw.getDocumentDOM().serverModel.getServerName() == "Cold Fusion") {
  1376.     fieldsStr = fieldsStr.replace(/#/g,"##");
  1377.     columnsStr = columnsStr.replace(/#/g,"##");      
  1378.   }
  1379.   
  1380.   paramObj.fieldsStr = fieldsStr;
  1381.   paramObj.columnsStr = columnsStr;
  1382. }
  1383. */
  1384.  
  1385. //--------------------------------------------------------------------
  1386. // FUNCTION:
  1387. //   checkThatCursorIsNotInsideOfAForm
  1388. //
  1389. // DESCRIPTION:
  1390. //   Before inserting a form, check that cursor is not inside of 
  1391. //   an existing form. If it is, set IP location to be just after the form
  1392. //
  1393. // ARGUMENTS:
  1394. //   None
  1395. //
  1396. // RETURNS:
  1397. //   Nothing
  1398. //--------------------------------------------------------------------
  1399. function checkThatCursorIsNotInsideOfAForm()
  1400. {
  1401.   var dom = dw.getDocumentDOM();
  1402.   var formNode = findForm(dom);
  1403.  
  1404.   if (formNode)
  1405.   { // if inside of a form tag
  1406.     formArr = dom.nodeToOffsets(formNode);
  1407.     dom.setSelection(formArr[1]+1,formArr[1]+1);
  1408.   }
  1409. }
  1410.  
  1411. //--------------------------------------------------------------------
  1412. // FUNCTION:
  1413. //   findForm
  1414. //
  1415. // DESCRIPTION:
  1416. //   Before inserting a form, check that cursor is not inside of 
  1417. //   an existing form. If it is, set IP location to be just after the form
  1418. //
  1419. // ARGUMENTS:
  1420. //   dom - DOM object
  1421. //
  1422. // RETURNS:
  1423. //   formObj
  1424. //--------------------------------------------------------------------
  1425. function findForm(dom)
  1426. {
  1427.   var formObj="";
  1428.   var selArr = dom.getSelection();
  1429.   var selObj = dom.offsetsToNode(selArr[0],selArr[1]);
  1430.  
  1431.   while (formObj=="" && selObj.parentNode)
  1432.   {
  1433.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName=="FORM")
  1434.       formObj=selObj;
  1435.     else
  1436.       selObj = selObj.parentNode;
  1437.   }
  1438.  
  1439.   return formObj;
  1440. }
  1441.  
  1442. //--------------------------------------------------------------------
  1443. // FUNCTION:
  1444. //   toggleSubmitAsVisibility
  1445. //
  1446. // DESCRIPTION:
  1447. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1448. //   the UI.  This menu should be visible for all items except text
  1449. //
  1450. // ARGUMENTS:
  1451. //   displayAs
  1452. //
  1453. // RETURNS:
  1454. //   Nothing
  1455. //--------------------------------------------------------------------
  1456. function toggleSubmitAsVisibility(displayAs)
  1457. {
  1458.   var currentVal = _SubmitAs.getValue();
  1459.   if ( displayAs != STATICTEXT && (currentVal == " " || !currentVal))
  1460.   { // if any form field is chosen in displayAs menu
  1461.     _SubmitAs.enable();
  1462.     _SubmitAs.del();
  1463.     var submitType = getSubmitTypeFromColumnType(ColumnTypes[_ColumnNames.getRowValue().column]);
  1464.     _SubmitAs.pickValue(submitType);
  1465.   }
  1466.   else if (displayAs == STATICTEXT)
  1467.   { // if plain text was chosen in displayAs menu
  1468.     _SubmitAs.append(" ");
  1469.     _SubmitAs.disable();
  1470.   }
  1471. }
  1472.  
  1473. //--------------------------------------------------------------------
  1474. // FUNCTION:
  1475. //   toggleLabelVisibility
  1476. //
  1477. // DESCRIPTION:
  1478. //   toggles the visibility of "Label: [textfield]" that appears on
  1479. //   the UI.  This textfield should be visible for all items except 
  1480. //   hidden fields
  1481. //
  1482. // ARGUMENTS:
  1483. //   displayAs
  1484. //
  1485. // RETURNS:
  1486. //   Nothing
  1487. //--------------------------------------------------------------------
  1488. function toggleLabelVisibility(displayAs)
  1489. {
  1490.   var labelFieldIsVisible = !( _ElementLabel.disabled == "true");
  1491.  
  1492.   if (displayAs != HIDDENFIELD && !labelFieldIsVisible)
  1493.   { // if non-hidden field & non-visible label field
  1494.     _ElementLabel.removeAttribute("disabled")                     // then make label field visible
  1495.       _ElementLabel.setAttribute("value",_ColumnNames.getRowValue().label); // and set value of it 
  1496.  
  1497.   }
  1498.   else if (displayAs == HIDDENFIELD && labelFieldIsVisible)
  1499.   {  // if hidden field
  1500.     _ElementLabel.setAttribute("value","");                          // then set value field to empty string
  1501.     _ElementLabel.setAttribute("disabled","true");                   // and make it non-editable
  1502.   }
  1503. }
  1504.  
  1505. //--------------------------------------------------------------------
  1506. // FUNCTION:
  1507. //   toggleSubmitAs
  1508. //
  1509. // DESCRIPTION:
  1510. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1511. //   the UI.  This menu is disabled in case of Update form and if
  1512. //   it is a primary key column
  1513. //
  1514. // ARGUMENTS:
  1515. //   show - boolean 
  1516. //
  1517. // RETURNS:
  1518. //   Nothing
  1519. //--------------------------------------------------------------------
  1520. function toggleSubmitAs(bShow)
  1521. {
  1522.   if (bShow)
  1523.   { 
  1524.     _SubmitAs.enabled();
  1525.   }
  1526.   else
  1527.   {
  1528.     _SubmitAs.append(" ");
  1529.     _SubmitAs.disable();
  1530.   }
  1531. }
  1532.  
  1533. //--------------------------------------------------------------------
  1534. // FUNCTION:
  1535. //   EnableDisableUpDownBtns
  1536. //
  1537. // DESCRIPTION:
  1538. //   Enable/disables the elemUp and elemDown buttons
  1539. //
  1540. // ARGUMENTS:
  1541. //   None
  1542. //
  1543. // RETURNS:
  1544. //   Nothing
  1545. //--------------------------------------------------------------------
  1546. function EnableDisableUpDownBtns()
  1547. {
  1548.   // Check if there are any columns
  1549.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1550.   {
  1551.     _ElemUp.setAttribute("disabled", true);
  1552.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  1553.     
  1554.     _ElemDown.setAttribute("disabled", true);
  1555.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  1556.   }
  1557.   else
  1558.   {
  1559.     if(_ColumnNames.list.length == 1)
  1560.       {
  1561.       // first row, so disable the up and down buttons
  1562.       _ElemDown.setAttribute("disabled", true);
  1563.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1564.  
  1565.       _ElemUp.setAttribute("disabled", true);
  1566.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1567.     }  
  1568.     if(_ColumnNames.list.length-1 == _ColumnNames.getRowIndex())
  1569.     {
  1570.       // last row, so disable the down button and enable the up button
  1571.       _ElemDown.setAttribute("disabled", true);
  1572.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1573.             
  1574.       _ElemUp.setAttribute("disabled", false);
  1575.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";
  1576.     }
  1577.     // first row, if it is disable up button and enable the down button
  1578.     else if (_ColumnNames.getRowIndex() == 0)
  1579.     {
  1580.       _ElemUp.setAttribute("disabled", true);
  1581.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1582.       
  1583.       _ElemDown.setAttribute("disabled", false);
  1584.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  1585.     }    
  1586.     else
  1587.     {
  1588.       //enable both up and down buttons
  1589.       _ElemDown.setAttribute("disabled", false);
  1590.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";
  1591.             
  1592.       _ElemUp.setAttribute("disabled", false);
  1593.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  1594.     }
  1595.   }
  1596. }
  1597.  
  1598.  
  1599. //--------------------------------------------------------------------
  1600. // FUNCTION:
  1601. //   EnableDisableAddDelBtns
  1602. //
  1603. // DESCRIPTION:
  1604. //   Enable/disables the elemAdd and elemDel buttons
  1605. //
  1606. // ARGUMENTS:
  1607. //   None
  1608. //
  1609. // RETURNS:
  1610. //   Nothing
  1611. //--------------------------------------------------------------------
  1612. function EnableDisableAddDelBtns()
  1613. {
  1614.   // Check if there are any columns
  1615.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1616.   {
  1617.     _ElemAdd.setAttribute("disabled", true);
  1618.     _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif";   
  1619.     
  1620.     _ElemDel.setAttribute("disabled", true);
  1621.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  1622.   }
  1623.   else
  1624.   {
  1625.     if (ColumnsToAdd.length == 0)
  1626.     {
  1627.       // no columns to add, so disable add button and enable delete button
  1628.       _ElemAdd.setAttribute("disabled", true);
  1629.       _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif"; 
  1630.       
  1631.       _ElemDel.setAttribute("disabled", false);
  1632.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";            
  1633.     }
  1634.     else
  1635.     {
  1636.       // enable both add and delete buttons
  1637.       _ElemAdd.setAttribute("disabled", false);
  1638.       _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif"; 
  1639.     
  1640.       _ElemDel.setAttribute("disabled", false);
  1641.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";                
  1642.     }
  1643.   }
  1644. }
  1645.  
  1646. //--------------------------------------------------------------------
  1647. // FUNCTION:
  1648. //   displayDynamicDataDialog
  1649. //
  1650. // DESCRIPTION:
  1651. //   pops up the dialog allowing the user to choose dynamic data
  1652. //
  1653. // ARGUMENTS:
  1654. //   textFieldObj
  1655. //
  1656. // RETURNS:
  1657. //   Nothing
  1658. //--------------------------------------------------------------------
  1659. function displayDynamicDataDialog(textFieldObj)
  1660. {
  1661.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  1662.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  1663.  
  1664.   if (expression)
  1665.   {
  1666. //    if (serverModel == "Cold Fusion")
  1667. //    {
  1668. //      expression = dwscripts.stripCFOutputTags(expression);
  1669. //    }
  1670.     textFieldObj.value = expression;
  1671.   }
  1672. }
  1673.  
  1674.  
  1675.  
  1676.  
  1677. //--------------------------------------------------------------------
  1678. // FUNCTION:
  1679. //   populateFormFieldStorageType
  1680. //
  1681. // DESCRIPTION:
  1682. //   This function is called by updateUI function.  It is responsible
  1683. //   for populating the Column grid.
  1684. //
  1685. // ARGUMENTS:
  1686. //   rowValObj - Column Name
  1687. //   rsName - Column Type
  1688. //   colName  - Recordset Name
  1689. //
  1690. // RETURNS:
  1691. //   Array
  1692. //--------------------------------------------------------------------
  1693. function populateFormFieldStorageType(rowValObj, rsName, colName)
  1694. {
  1695.   // note: this fn is only called when the row is first created, which is why
  1696.   // it only lists some of the available form types
  1697.   var displayType = rowValObj.displayAs.type;
  1698.   var dynDataVal = createDynamicData(rsName,colName);
  1699.   
  1700.   rowValObj.defaultStr = dynDataVal;
  1701.  
  1702.   if (displayType == "textField" || 
  1703.       displayType  == "textArea" || 
  1704.       displayType  == "hiddenField" )
  1705.   {
  1706.     rowValObj.displayAs.value = dynDataVal;
  1707.   }
  1708.   else if (displayType == "text" )
  1709.   {
  1710.     rowValObj.displayAs.text = dynDataVal;
  1711.   }
  1712.   else if (displayType == "dynamicCheckBox")
  1713.   {
  1714.     rowValObj.displayAs.checkIf = dynDataVal;
  1715.   }
  1716.  
  1717.   return rowValObj;
  1718. }
  1719.  
  1720.  
  1721. //--------------------------------------------------------------------
  1722. // FUNCTION:
  1723. //   createDynamicData
  1724. //
  1725. // DESCRIPTION:
  1726. //   Pops up the dialog allowing the user to choose dynamic data
  1727. //
  1728. // ARGUMENTS:
  1729. //   rs - Recordset
  1730. //   col - Column Name
  1731. //
  1732. // RETURNS:
  1733. //   String
  1734. //--------------------------------------------------------------------
  1735. function createDynamicData(rs,col)
  1736. {
  1737.   var retVal = "";
  1738.   if (rs){
  1739.     var colArray = dwscripts.getFieldNames(rs);
  1740.     if (dwscripts.findInArray(colArray, col) != -1){
  1741.       var paramObj = new Object();
  1742.       paramObj.sourceName = rs;
  1743.       paramObj.bindingName = col;
  1744.  
  1745.       retVal = extPart.getInsertString("", "Recordset_DataRef", paramObj);
  1746.     }
  1747.   }
  1748.   return retVal;
  1749. }
  1750.  
  1751.  
  1752. //--------------------------------------------------------------------
  1753. // FUNCTION:
  1754. //   updateDefaultFormFieldValues
  1755. //
  1756. // DESCRIPTION:
  1757. //   Goes through the default values, and replace references to the old
  1758. //   recordset with the new recordset
  1759. //
  1760. // ARGUMENTS:
  1761. //   oldRS - old Recordset
  1762. //   newRS - new Recordset
  1763. //
  1764. // RETURNS:
  1765. //   Nothing
  1766. //--------------------------------------------------------------------
  1767. function updateDefaultFormFieldValues(oldRS, newRS)
  1768. {
  1769.   var rowObjs = _ColumnNames.valueList;
  1770.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  1771.  
  1772.   for (i=0;i<nRows;i++)
  1773.   {
  1774.     currRowObj = rowObjs[i];
  1775.     regExp = new RegExp(oldRS,"g");
  1776.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp,newRS);
  1777.     currRowObj.passwordStr = currRowObj.passwordStr.toString().replace(regExp,newRS);
  1778.  
  1779.     // update the current display
  1780.     switch(currRowObj.displayAs.type)
  1781.     {
  1782.       case "textField":
  1783.       case "textArea":
  1784.       case "hiddenField":
  1785.         currRowObj.displayAs.value = currRowObj.defaultStr;
  1786.         break;
  1787.       case "passwordField":
  1788.         currRowObj.passwordField.value = currRowObj.passwordStr;
  1789.         break;
  1790.       case "text":
  1791.         currRowObj.displayAs.text = currRowObj.defaultStr;
  1792.         break;
  1793.       case "radioGroup":
  1794.       case "dynamicRadioGroup":
  1795.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  1796.         break;
  1797.       case "menu":
  1798.       case "dynamicMenu":
  1799.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  1800.         break;
  1801.       case "dynamicCheckBox":
  1802.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  1803.         break;
  1804.       case "default":
  1805.         break;  
  1806.     }
  1807.   } 
  1808.  
  1809. }
  1810.  
  1811.  
  1812. //--------------------------------------------------------------------
  1813. // FUNCTION:
  1814. //   getRedirectURL
  1815. //
  1816. // DESCRIPTION:
  1817. //   Returns the given URL with a query string added or removed, based
  1818. //   on the includeQuery boolean
  1819. //
  1820. // ARGUMENTS:
  1821. //   origURL - string - the URL to update
  1822. //   includeQuery - boolean - true to add the query string, false to
  1823. //     remove it.
  1824. //
  1825. // RETURNS:
  1826. //   string
  1827. //--------------------------------------------------------------------
  1828.  
  1829. function getRedirectURL(origURL, includeQuery)
  1830. {
  1831.   var retVal = origURL;
  1832.   
  1833.   if (includeQuery)
  1834.   {
  1835.     if (!origURL)
  1836.     {
  1837.       retVal = "#CurrentPage#?#CGI.QUERY_STRING#";
  1838.     }
  1839.     else
  1840.     {
  1841.       if (origURL.indexOf("?") == -1)
  1842.       {
  1843.         retVal += "?#CGI.QUERY_STRING#";
  1844.       }
  1845.       else
  1846.       {
  1847.         retVal += "&#CGI.QUERY_STRING#";
  1848.       }
  1849.     }
  1850.   }
  1851.   else
  1852.   {
  1853.     var regExp = /[?&]#CGI\.QUERY_STRING#/i;
  1854.     var match = origURL.match(regExp);
  1855.     if (match && match.length > 0)
  1856.     {
  1857.       var endOffset = match.index + match[0].length;
  1858.       if (endOffset == origURL.length)
  1859.       {
  1860.         retVal = origURL.substring(0,match.index);
  1861.       }
  1862.       else
  1863.       {
  1864.         retVal = origURL.substring(0,match.index+1) + origURL.substring(match.index + match[0].length + 1);
  1865.       }
  1866.     }
  1867.   }
  1868.   
  1869.   return retVal;
  1870. }
  1871.  
  1872.  
  1873. //--------------------------------------------------------------------
  1874. // FUNCTION:
  1875. //   hasQueryString
  1876. //
  1877. // DESCRIPTION:
  1878. //   Returns true if the given URL has the query string added
  1879. //
  1880. // ARGUMENTS:
  1881. //   redirectURL - string - the URL to check
  1882. //
  1883. // RETURNS:
  1884. //   boolean
  1885. //--------------------------------------------------------------------
  1886.  
  1887. function hasQueryString(redirectURL)
  1888. {
  1889.   var retVal = false;
  1890.   
  1891.   var regExp = /[?&]#CGI\.QUERY_STRING#/i;
  1892.   
  1893.   retVal = (redirectURL.search(regExp) != -1);
  1894.  
  1895.   return retVal;
  1896. }
  1897.  
  1898.  
  1899.